Obtain the File Name of an Uploaded File
In many situations, it is desirable to obtain the name of a file previously uploaded in order to perform different actions, such as validating if the file has a specific extension, a certain number of characters, etc.
To obtain the name of a file uploaded, you must create an expression. In it, you obtain the list of files uploaded in a file-type attribute and go through each record of the array, extracting the name of each one.
The following expression shows how the name of a file stored in the Documents file-type attribute (from the Business Opportunity entity) is obtained, assuming there is only one file uploaded in it. The name obtained is then displayed to the user through a validation message by using the CHelper.ThrowValidationError
function. This expression is executed when Save is clicked in the form of a task for testing purposes.
//Obtain array of files
var UploadedFile = Me.getXPath("BusinessOpportunity.RelatedDocuments");
//Validate there are files in the array
if(UploadedFile.size() > 0){
//Obtain the file. Remember we assumed there is only 1, so the position of the array is 0
var Filename = UploadedFile.get(0).getXPath("FileName");
// Show the Filename
CHelper.ThrowValidationError("File name =" + Filename);
}
From the Work Portal in the form where the expression was configured, you can validate that the file name is correctly returned.